import { BaseController, CoolController } from "@cool-midway/core";
import { ProviderOverviewService } from "../../service/overview";
import { ProviderVisitLogService } from "../../service/visit_log";
import { Get, Inject, Query } from "@midwayjs/core";
import { Context } from "@midwayjs/koa";

@CoolController({
    service: ProviderOverviewService,
})
export class AppProviderOverviewController extends BaseController {
    @Inject()
    providerOverviewService: ProviderOverviewService;

    @Inject()
    providerVisitLogService: ProviderVisitLogService;

    @Inject()
    ctx: Context;


    @Get('/overview', { summary: '获取服务人员概览' })
    async overview(@Query('id') id: number) {
        if (this.ctx.user?.id) {
            this.providerVisitLogService.record(id, this.ctx.user.id).catch(err => {
                console.error('记录访问日志失败', err);
            });
        }
        return this.ok(await this.providerOverviewService.overview(id));
    }
}
